package com.wj.blog.controller;

import afu.org.checkerframework.checker.oigj.qual.O;
import com.wj.blog.pojo.Link;
import com.wj.blog.service.LinkService;
import com.wj.blog.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Author:   wj
 * Date:     2020/4/14 14:45
 * Description: 友情链接
 */
@RestController
@RequestMapping("/link")
public class LinkController {
    @Autowired
    LinkService linkService;

    @PostMapping("/save")
    public Result<Object> save(@RequestBody Link link){
        linkService.save(link);
        return new Result("添加成功");
    }

    @DeleteMapping("/delete/{id}")
    public Result<Object> delted(@PathVariable Integer id){
        linkService.delted(id);
        return new Result("删除成功");
    }

    @PutMapping("/update")
    public Result<Object> update(@RequestBody Link link){
        linkService.update(link);
        return new Result<Object>("修改成功");
    }

    @GetMapping("/listBack")
    public Result<Object> listBack(){
       List<Link> links =  linkService.listBack();
        return new Result<>(links);
    }

    @GetMapping("{id}")
    public Result<Object> getById(@PathVariable Integer id){
        Link link = linkService.getById(id);

        return new Result<>(link);
    }
}
